import socket, time

SERVER="fe80::215:17ff:fe62:9d7f"
PORT=7775
#SERVER="10.1.1.2"
SIZE=1310

class Client:

    def __init__(self, data):
        self.data = data
        self.sock = socket.socket(socket.AF_INET6)
        self.sock.connect((SERVER, PORT,0,2))

    def run(self):
        start_time = time.time()
        end_time = start_time
        bytes = 0
        requests = 0
        while(end_time - start_time < 10):
            bytes += self.sock.send('a' * SIZE)
            requests += 1
            time.sleep(.001)
            end_time = time.time()
        self.sock.shutdown(socket.SHUT_RDWR)
        self.sock.close()
        self.data.updateRateTotal(bytes / (end_time - start_time), requests / (end_time - start_time))
        

class Data:

    def __init__(self):
        self.rate = 0
        self.requests = 0

    def updateRateTotal(self, new_rate, requests):
        self.rate += new_rate
        self.requests += requests

    def printData(self):
        # output = open(self.filename, 'w')
        # output.write("%.02f\n%.02f\n"%((self.rate * 8 / 1024 / 1024),(self.requests / 1000)))
        print "%.02f,%.02f"%((self.requests/1000),(self.rate * 8 / 1024/ 1024))
        

if __name__ == "__main__":

    data = Data()

    client = Client(data)
    client.run()

    data.printData()
